package com.luanye.enjoy.controller;

import com.luanye.enjoy.dto.ApplyFormDTO;
import com.luanye.enjoy.dto.CityDTO;
import com.luanye.enjoy.service.VillageService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

@RestController
@RequestMapping("/village")
@AllArgsConstructor
public class VillageController {

    private final VillageService villageService;

    @PostMapping("/apply")
    public RespBean apply(@RequestBody @Valid ApplyFormDTO dto) {
        return villageService.apply(dto);
    }

    @GetMapping("/process")
    public RespBean getApply() {
        return villageService.getForm();
    }

    @GetMapping("/list")
    public RespBean list(@RequestParam(value = "current", defaultValue = "1") Integer current,
                         @RequestParam(value = "x", required = false) Double x,
                         @RequestParam(value = "y", required = false) Double y) {
        return villageService.listByGeo(current, x, y);
    }

    @GetMapping("/city/list")
    public RespBean getCityList(){
        return villageService.getCityList();
    }

    @PostMapping("/by")
    public RespBean getVillageListByCity(@RequestBody CityDTO dto){
        return villageService.getVillageListByCity(dto);
    }

    @GetMapping("/detail/{id}")
    public RespBean getDetail(@PathVariable("id") Long id){
        return villageService.getDetail(id);
    }
}
